# coding=utf-8
import os
import eyed3
def getMp3Files(parent):
mp3Files = []
sons = os.listdir(parent)
if (isinstance(sons, list)):
for n in sons:
# print("{} {}".format(n, os.sep.join((parent, n))))
sonPath = os.sep.join((parent, n))
if (os.path.isdir(sonPath)):
grandChildren = getMp3Files(sonPath)
# print("mepath {}, {}".format(sonPath, grandChildren))
mp3Files.extend(grandChildren)
elif os.path.isfile(sonPath) and len(sonPath) > 3:
suffix = sonPath[len(sonPath)-4:]
if suffix == ".mp3":
mp3Files.append(sonPath)
else:
pass
return mp3Files
def dealOneMp3(path):
audio = eyed3.load(path)
title = audio.tag.title
fn = os.path.basename(path)
parentPath = os.path.dirname(path)
parent = os.path.basename(parentPath)
audio.tag.title = parent + "_" + fn
audio.tag.save()
mp3 = eyed3.load(path)
print("{} {} {} {}".format(path, title, fn, mp3.tag.title))
def dealAll(allPath):
for p in allPath:
dealOneMp3(p)
if __name__ == "__main__":
all = getMp3Files(os.path.abspath("."))
# print("\n".join(all))
# print(len(all))
dealAll(all)
y
用mutagen修改mp3歌曲名
# coding=utf-8
import os
import eyed3
from mutagen.id3 import ID3, TIT2, APIC, TPE1, TALB
def getMp3Files(parent):
mp3Files = []
sons = os.listdir(parent)
if (isinstance(sons, list)):
for n in sons:
# print("{} {}".format(n, os.sep.join((parent, n))))
sonPath = os.sep.join((parent, n))
if (os.path.isdir(sonPath)):
grandChildren = getMp3Files(sonPath)
# print("mepath {}, {}".format(sonPath, grandChildren))
mp3Files.extend(grandChildren)
elif os.path.isfile(sonPath) and len(sonPath) > 3:
suffix = sonPath[len(sonPath)-4:]
if suffix == ".mp3":
mp3Files.append(sonPath)
else:
pas